﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.Platform
{
    public class DataViewContainerDictService : CrudAppService<DataViewContainerDict, DataViewContainerDictDto, Guid, DataViewContainerDictInput, DataViewContainerDictCreateDto, DataViewContainerDictUpdateDto>
    {
        private IRepository<DataViewContainerDict, Guid> _stConfigRepository;

        public DataViewContainerDictService(IRepository<DataViewContainerDict, Guid> StConfigRepository) : base(StConfigRepository)
        {
            _stConfigRepository = StConfigRepository;
        }

        /// <summary>
        /// 获取标准单词
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<DataViewContainerDictDto>> GetListAsync(DataViewContainerDictInput input)
        {
            var iQuery = await _stConfigRepository.GetQueryableAsync();
            iQuery = iQuery.WhereIf(!string.IsNullOrEmpty(input.Filter), i => i.ViewContainerName.Contains(input.Filter));

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<DataViewContainerDict>, List<DataViewContainerDictDto>>(iQuery.ToList());

                return new PagedResultDto<DataViewContainerDictDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<DataViewContainerDict>, List<DataViewContainerDictDto>>(items.ToList());

                return new PagedResultDto<DataViewContainerDictDto>(totalCount, itemsDto);
            }
        }
    }
}
